package com.jwd.mybatis.mapper

import com.jwd.mybatis.SLoginUser
import com.jwd.mybatis.SRole
import com.jwd.mybatis.SUser
import com.jwd.mybatis.SUserRole
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select

/**
 * Created by udi on 2017.3.6.
 */
@Mapper
interface UserMapper {
    @Select("select * from s_user where login_name = #{login_name}")
    fun findByLoginName(@Param("login_name") login_name: String): SUser

    @Select("select r.* from s_role r join s_user_role ur on (r.id = ur.role_id) where ur.user_id = #{user_id}")
    fun findRolesByUserId(@Param("user_id") user_id: Int): List<SRole>

    @Select("select * from s_login_user where user_id = #{user_id}")
    fun  findLoginUserByUserId(userId: Int): SLoginUser
}